<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="../frame/layui/css/layui.css">
    <link rel="stylesheet" href="../frame/static/css/style.css">
    <link rel="icon" href="../frame/static/image/code.png">
</head>
<body class="body">
<div>
    <ins class="adsbygoogle" style="display:inline-block;width:970px;height:20px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="6835627838"></ins>
</div>

	<button type="button" class="layui-btn" id="test1" name = "img">
  	<i class="layui-icon">&#xe67c;</i>上传图片
	</button> 
	<img id = "img" height="160px" width="160px" />
	<div>
    <ins class="adsbygoogle" style="display:inline-block;width:970px;height:20px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="6835627838"></ins>
</div>
<form class="layui-form layui-form-pane" action="/resource/addResource" method = "post"> 
  
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">资源位置</label>
        <div class="layui-input-block">
            <select name="type" lay-filter="aihao">
                <option value="1" selected="">明星信息</option>
                <option value="2">上方显示</option>
                <option value="3">下方显示</option>
                <option value="4">Banner图</option>
                <option value="5">底部纯文字</option>
            </select>
        </div>
    </div>
	<input type="hidden" value="" id = "imgUrl" name = "imgUrl">
	<input type="hidden" value="1" id = "userId" name = "userId">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">文本域</label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="../frame/layui/layui.js" charset="utf-8"></script>
<script>

	layui.use('upload', function(){
		  var upload = layui.upload;
		   
		  //执行实例
		  var uploadInst = upload.render({
		    elem: '#test1' //绑定元素
		    ,url: 'http://152.136.136.209:8081/file/upload' //上传接口
		    ,done: function(res){
		      //上传完毕回调
		      if(res.code==200){
		    	  alert(res.msg);
		    	  document.getElementById('img').setAttribute("src",res.data.imgUrl);
		    	  document.getElementById('imgUrl').value = res.data.imgUrl;
		      }else{
		    	  alert(res.msg);
		      }
		    }
		    ,error: function(){
		      //请求异常回调
		    }
		  });
		});



    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 2){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        //form.on('submit(demo1)', function(data){
        //    layer.alert(JSON.stringify(data.field), {
         //       title: '最终的提交信息'
         //   });
            
          //  return false;
       // });


    });
</script>
</body>
</html>